
#ifndef   ZGW_HID_HAL_H
#define    ZGW_HID_HAL_H

#include "bt_types.h"



#define  HID_ADDR_BASE  0x40200000
#define  PMU_ADDR_BASE	0x40250000

#define  NUM_OF_HARD_FIFO  16		// hardware fifio num
#define  MAX_HID_FIFO_NUM   24	// Software fifo num   24 or 256


#define HID_KEY_REG    0x3c

// LED

#define  LED_ALWAYS_DARK			0x01
#define  LED_ALWAYS_LIGHT           0x02
#define  LED_FLASH					0x03
#define  LED_MOTOR					0x04

// keyboard  macros & registers
#define KEYBOARD_COLUMNS                         18
#define KEYBOARD_ROWS                            8

#define NOKEY   0x0000

#define  KEYBOARD_STATUS_OFFSET  	0xa4

#define   KEYBOARD_STATUS_GHOST   	0x02   // 1 = Invalid 0 = normal
#define   KEYBOARD_STATUS_FULL      0x04  // 1 = full 0 = last one
#define   KEYBOARD_STATUS_OVERFLOW  0x08  // 1 = Invalid 0 = normal
//  hid fifo start address  len = 16bytes
#define   KEYBOARD_FIFO_OFFSET   	0xa8


// mouse macros & registers
#define  MOUSE_X_DATA				0x90
#define  MOUSE_Y_DATA				0x94
#define  MOUSE_STATUS				0x9c

// wii macros & registers
#define  PWM_SELECT_EN				0x30
//#define  PWM_MODE_SEL				0x1c
#define  PWM_INI_LOW				0xf0
#define  PWM_INI_HIGH				0xf4
#define  PWM_TOGGLE_LOW				0xf8
#define  PWM_TOGGLE_HIGH			0xfc


// pmu registers

#define  PMU_MODE_SEL				PMU_ADDR_BASE+0x106
#define  PMU_CHANNEL_SEL			PMU_ADDR_BASE+0x108
#define  PMU_VOLTAGE_VAL			PMU_ADDR_BASE+0x120



#define MOS_NONE    0
#define MOS_XY      (1 << 3)
#define MOS_Z       (1 << 2)
#define MOS_BUTN    (1 << 0)





#define HID_READ_REG(a)		(*((volatile u_int8 *)(a+HID_ADDR_BASE)))

#define HID_WRITE_REG(a,v)  	\
	(*(volatile u_int8  *)(a+HID_ADDR_BASE) = (v))
	//HWdelay_Wait_For_us(10)

#define HID_READ_REG_UINT32(a)			(*((volatile u_int32 *)(a+HID_ADDR_BASE)))
#define HID_WRITE_REG_UINT32(REG,VAL)   (*(volatile u_int32*)(REG+HID_ADDR_BASE)) = (u_int32)(VAL) 





typedef void (*t_hid_KB_Read)(void);
typedef  void (*t_HID_PIN_SM)(void);
typedef void (*t_hid_init)(void);
typedef void (*t_hid_isr)(void); 
typedef void (*t_hid_led)(u_int8  num, u_int8 mode, u_int16 toggle);
typedef void (*t_hid_pwm)(u_int8 onOff,u_int16  initial, u_int16  toggle);
typedef u_int16  (*t_hid_adc)(u_int8 channel);
typedef void (*t_hid_sched)(void);
typedef void (*t_hid_Set_KB_Lock_LED)(u_int8 flag);
typedef void (*t_hid_lm_connect_comp)(u_int8 result,u_int16 handle);
typedef void (*t_hid_discon_comp)(u_int8 result);
typedef void (*t_hid_spp_rxData)(u_int8 *ptr, u_int8 length);
typedef void (*t_hid_l2cap_connect_comp)(u_int16 handle);
typedef void (*t_hid_rx_ack)(u_int16 handle);
typedef void (*t_hid_link_sniff_timeout)(void *arg);






void HID_Init_HAL(void);
void HID_ISR(void);
void  HID_Set_PWM(u_int8 onOff,u_int16  initial, u_int16  toggle);          // 0:off 1: on
void  HID_Set_LED(u_int8  num, u_int8 mode,u_int16 toggle);
void  HID_GPIO_write (u_int8 num, u_int8 value);
u_int8  HID_GPIO_read (u_int8 num);
u_int16  HID_Get_ADC(u_int8 channel);
void HID_Send_UART(const u_int8 *ptr_fifo, u_int32 length);
void HIDMain_Handle_Message(u_int16 msg_id, void* msg_data);
void HID_Pskey_Init(u_int8 *data);
void HID_Set_KB_Lock_Char_LED(u_int8 flag);
void HID_LM_Connect_Complete(u_int8 result,u_int16 handle);
void HID_Disconnect_Complete(u_int8 result);
void HID_Schedule(void);
void HID_RoleChange(u_int8 result);

void HID_3rd_LED(u_int8  num,u_int16 init, u_int16 toggle);
void HID_spp_rx_data_1(u_int8 *ptr, u_int8 length);
void HID_spp_rx_data_2(u_int8 *ptr, u_int8 length);
void HID_L2cap_Connect_Complete(u_int16 handle);
void HID_rx_ack(u_int16 handle);



#endif
